﻿using System.Linq;

namespace Basmus.Values
{
    public class ContainsCondition : ICondition
    {
        public ContainsType Type { get; private set; }

        public object[] Values { get; private set; }

        public ContainsCondition(ContainsType containsType, object[] values)
        {
            Type = containsType;
            Values = values;
        }

        public bool Check(object[] values)
        {
            if (values != null && Values != null)
            {
                var check = (Type == ContainsType.Not && values.All(x => !Values.Contains(x))) ||
                            (Type == ContainsType.Any && values.Any(x => Values.Contains(x))) ||
                            (Type == ContainsType.All && values.All(x => Values.Contains(x)));
                return check;
            }
            return Type != ContainsType.Not && (values == null && Values == null);
        }
    }
}